import sys
import datetime as dt
import numpy as np
import pandas as pd
from data_read.get_feature import Get_feature_data
from data_read.get_label import Get_label_data
from training.ml_frame.step_rolling.data_split_step import Rolling_train_twoset
# from ml_train import Ml_rolling_trin
from training.ml_frame.step_rolling.IC_record import Ic_record
import operator
import os
# 保证处理矩阵为n*50

class Quant():
    def __init__(self, args) -> None:
        for k, v in args.time_param.items():
            args.time_param[k] = dt.datetime.strptime(v, '%Y-%m')
        self.args = args 

    def get_data(self, Get_feature=Get_feature_data, Get_label=Get_label_data):
        gf = Get_feature(self.args)
        feature, codes_f, times_f = gf.get_feature()
        gl = Get_label(self.args)
        label, codes_l, times_l = gl.get_label_reg()
        print('检查feature与labe时间索引是否对齐：', operator.eq(times_f.tolist(), times_l.tolist()))
        print('检查feature与labe品种索引是否对齐：', operator.eq(codes_f.tolist(), codes_l.tolist()))
        print(f'使用特征数量：{len(self.args.feature_list)} 具体为： {self.args.feature_list}')
        if  self.args.varieties is not None:
            print(f'使用品种数量：{len(self.args.varieties)} 具体为： {self.args.varieties}')
        return feature, label, codes_f, times_f   
                       
    def rolling_train(self, codes, times, feature, label):
        ml_train = Rolling_train_twoset(feature, label, codes, times, self.args)
        ic_re = Ic_record(self.args, codes)
        train_pred_df, train_true_df, test_pred_df, test_true_df, train_times, test_times = ml_train.rolling_train()
        ic_re.ic_record(train_pred_df, train_true_df, train_times, 'train')
        ic_re.ic_record(test_pred_df, test_true_df, test_times, 'test')
        


            

            
            
        
        